<template>

	<swiper class="topView" indicator-dots="true" autoplay="true" :interval="interval" duration="400">
		<swiper-item v-for="(item, index) in imgList" :key="index" @click="imgClick(item)">

			<view class="topView">
				<image class="topView" :src="(item.poster) "  mode="widthFix" lazy-load="true" :data-index="index" @tap="previewPhoto">

				</image>
			</view>


		</swiper-item>


	</swiper>


</template>

<script>
	export default {
		props: {
			// 时间间隔
			interval: {
				type: [Number, String],
				default: 2000
			},
			// 轮播图数组数据
			imgList: {
				type: Array,
				default () {
					return []
				}
			}


		},
		data() {
			return {

			}
		},
		methods: {

			imgClick(item) {
				this.$emit('click', item)
			},
			/* 预览照片 */
			previewPhoto(e) {
				let index = e.currentTarget.dataset.index;
				let list = this.imgList.map((item, index) => {
					return item.poster;
				});
			
				uni.previewImage({
					current: list[index],
					urls: list,
					longPressActions: {
						itemList: ['保存图片'],
						success: function(res) {
			
							uni.getImageInfo({
								src: list[res.index],
								success: function(image) {
									console.log('图片信息：', JSON.stringify(image));
									uni.saveImageToPhotosAlbum({
										filePath: image.path,
										success: function() {
											uni.showToast({
												title: '图片保存成功',
												icon: 'none',
												duration: 3000
											});
										}
									});
								}
							});
						}
					}
				});
			},
			
			
			
		}
	}
</script>

<style scoped>
	.topView {
		margin-top: 0;
		margin-left: 0;
		width: 100vw;
		height: 66vw;
	}
</style>